package reporter

import (
	"gorm.io/gorm"
	"gorm.io/plugin/soft_delete"
	"time"
	"xkginweb/global"
)

// 上报人员表

type QccReporter struct {
	ReporterId  uint                  `gorm:"primary_key;AUTO_INCREMENT;comment:主键ID" json:"reporter_id"`
	CreatedAt   global.LocalTime      `gorm:"type:datetime;comment:创建时间" json:"created_at"`
	UpdatedAt   global.LocalTime      `gorm:"type:datetime;comment:更新时间" json:"updated_at"`
	IsDeleted   soft_delete.DeletedAt `gorm:"type:bigint(20) unsigned;default:0;comment:是否删除" json:"is_deleted"`
	Username    string                `gorm:"type:varchar(50);unique;comment:账号;NOT NULL" json:"username"`
	Password    string                `gorm:"type:varchar(50);comment:密码;NOT NULL" json:"password"`
	Name        string                `gorm:"type:varchar(50);default:'';comment:名字;NOT NULL" json:"name"`
	Sex         int8                  `gorm:"type:int(11);default:3;comment:性别 1男 2女 3其他" json:"sex"`
	Birthdate   *time.Time            `gorm:"type:datetime;comment:出生日期;" json:"birthdate"`
	PhoneNumber string                `gorm:"type:varchar(20);default:'';comment:手机号（同账号）;NOT NULL" json:"phone_number"`
	Address     string                `gorm:"type:text;default:'';comment:地址" json:"address"`
	Type        string                `gorm:"type:varchar(50);default:'';comment:用户职责" json:"type"`
	Enable      int8                  `gorm:"type:int(11);default:1;comment:户是否被冻结 1正常 2冻结" json:"enable"`
}

func (QccReporter) TableName() string {
	return "qcc_reporter"
}

func (u *QccReporter) BeforeSave(*gorm.DB) error {
	if u.Birthdate != nil && u.Birthdate.IsZero() {
		u.Birthdate = nil
	}
	return nil
}
